<?php

namespace App\Model\Content;

use App\Model\CrudModel;

/**
 * @property int $id
 * @property string $name
 * @property string $code
 * @property string $remark
 */
class AdGroupModel extends CrudModel
{
    // 配置
    protected ?string $table = 'ad_group';

    protected array $adminPageListField = [
        'id','code','name','remark',
    ];

    public function addOne(array $data)
    {
        $add = [
            'name' => trim($data['name']),
            'code' => trim($data['code']),
            'remark' => trim($data['remark']),
        ];
        return $this->normalAddOne($add);
    }

    public function updateById($id, array $data)
    {
        return $this->buildQuery(['id'=>$id,])->update([
            'name' => trim($data['name']),
            'code' => trim($data['code']),
            'remark' => trim($data['remark']),
            'updated_at' => time(),
        ]);
    }

    /**
     * @param $code
     * @param $field
     * @return static
     */
    public function findByCode($code, $field=['*'])
    {
        return $this->buildQuery(['code'=> $code])->first($field);
    }

}